package com.demo.springmvc.controller;

import com.demo.springmvc.common.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class HelloController {
    @RequestMapping("/testtest")
    public String test(Model model){
        System.out.println("已经到达控制器了");
        model.addAttribute("name","张丹丹");
        return "ok";//字符串就是一个视图 ok.jsp
    }

//    name=hkx&age=36&password=999
//    1. 直接获取,如果采用基本类型作为参数，需要指定一个默认值
//    2. javaBean 获取
    @RequestMapping("/parm")
    public String parm(User user, String name, @RequestParam(defaultValue = "0")int age, @RequestParam(value = "password",defaultValue = "") String pwd){
        System.out.println("!!!!");
        return "ok";
    }

//    用数组或集合获取一个参数，多个值
    @RequestMapping("/parm2")
    public String parm2(@RequestParam int[] id, @RequestParam("id")List<Integer> ids){
        return "ok";
    }


}
